package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import com.zzyl.vo.NursingProjectPlanVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划")
public class NursingPlanController {
    @Autowired
    private NursingPlanService nursingPlanService;

    @GetMapping("/search")
    @ApiOperation("条件分页查询")
    public ResponseResult<PageResponse<NursingPlanVo>> pageNursingPlan(@ApiParam("护理计划名称") @RequestParam(value = "name", required = false) String name,
                                                                       @ApiParam("页码（默认为1）") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                       @ApiParam("每页大小（默认为10）") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                                       @ApiParam("护理计划状态") @RequestParam(value = "status", required = false) Integer status) {
        PageResponse<NursingPlanVo> pageResponse = nursingPlanService.pageNursingPlan(name, pageNum, pageSize, status);
        return ResponseResult.success(pageResponse);
    }

    @ApiOperation("新增")
    @PostMapping()
    public ResponseResult addNursingPlan(@RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.addNursingPlan(nursingPlanDto);
        return ResponseResult.success();
    }

    @ApiOperation("根据id查询")
    @GetMapping("/{id}")
    public ResponseResult<NursingPlanVo> getNursingPlanById(@PathVariable(value = "id") Integer id) {
        NursingPlanVo nursingPlanVo = nursingPlanService.getNursingPlan(id);
        return ResponseResult.success(nursingPlanVo);
    }

    @ApiOperation("修改")
    @PutMapping("/{id}")
    public ResponseResult updateNursingPlan(@RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.updateNursingPlan(nursingPlanDto);
        return ResponseResult.success();
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public ResponseResult deleteNursingPlan(@PathVariable(value = "id") Integer id) {
        nursingPlanService.deleteNursingPlan(id);
        return ResponseResult.success();
    }

    @ApiOperation("启用禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult forbiddenNursingPlan(@PathVariable(value = "id") Integer id,
                                               @PathVariable(value = "status") Integer status) {
        nursingPlanService.forbiddenNursingPlan(id, status);
        return ResponseResult.success();
    }

    @ApiOperation("查询所有护理计划")
    @GetMapping
    public ResponseResult<List<NursingPlanVo>> getAllNursingPlan() {
        List<NursingPlanVo> nursingPlanVos = nursingPlanService.getAllNursingPlan();
        return ResponseResult.success(nursingPlanVos);
    }
}
